package com.hsh.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatUtil {
    private static SimpleDateFormat format =
//            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            new SimpleDateFormat("yyyy-MM-dd");

    public static String format(Date date) {
        return format.format(date);
    }

    public static Date cutDate(Date date, Integer frontDay) {
        return new Date(date.getTime() - 1000 * 3600 * 24 * frontDay);
    }

    public static long parse(String time) {
        try {
            return format.parse(time).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static Date parseDate(String time) {
        try {
            return format.parse(time);
        } catch (ParseException e) {
            return null;
//            e.printStackTrace();
        }
    }

}
